# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :create_flask.py
# @Time     e :2022/5/27 14:12
# @Author    :张志坤

from flask import Flask
from flask_cors import CORS
from models import db
from views.users import user_bp
from common.utils.jwt_auth import jwt_authentication
from views.channel import channel_bp
from views.comment import comment_bp
from views.news import news_bp

def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(channel_bp)
    app.register_blueprint(comment_bp)
    app.register_blueprint(news_bp)
    # 添加钩子  每次请求前校验登录
    app.before_request(jwt_authentication)
    # 初始化整个项目
    db.init_app(app)
    # 跨域
    CORS(app)

    return app
